C++ function templates, function name confusion. This is funny [migrated]
Posted
by
nashmaniac
on Programmers
See other posts from Programmers
or by nashmaniac
Published on 2012-11-10T15:59:49Z
Indexed on
2012/11/10
23:16 UTC
Read the original article
Hit count: 224
Alright so heres the program and works absolutely right
#include <iostream>
using namespace std;
template <typename T>
void Swap(T &a , T &b);
int main(){
int i = 10;
int j = 20;
cout<<"i, j = " << i <<" , " <<j<<endl;
Swap(i,j);
cout<<"i, j = " << i <<" , " <<j<<endl;
}
template <typename T>
void Swap(T &a , T &b){
T temp;
temp = a ;
a = b;
b= temp;
}
but when I change the function's name from Swap to swap it generates an error saying
error: call of overloaded 'swap(int&, int&)' is ambiguous| note: candidates are: void swap(T&, T&) [with T = int]| ||=== Build finished: 1 errors, 0 warnings ===|
what happened is it a rule to start functions using templates to start with a capital letter ?
© Programmers or respective owner